//
//  VideoFullScreenController.m
//  AVPlayer
//
//  Created by dllo on 16/6/5.
//  Copyright © 2016年 xuxiwen. All rights reserved.
//

#import "VideoFullScreenController.h"
#import "ZFPlayer.h"

@interface VideoFullScreenController ()
@property (nonatomic, strong) ZFPlayerView *playerView;
@end

@implementation VideoFullScreenController



- (instancetype)initWithQYXDailyItemListModel:(QYXDailyItemListModel *)model;
{
    
    self = [super init];
    if (self) {
        
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        self.playerView = [[ZFPlayerView alloc] init];
        [self.view addSubview:self.playerView];
        [self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(0);
            make.left.right.equalTo(self.view);
            // 注意此处，宽高比16：9优先级比1000低就行，在因为iPhone 4S宽高比不是16：9
            make.height.equalTo(self.playerView.mas_width).multipliedBy(9.0f/16.0f).with.priority(750);
        }];
        
        NSMutableDictionary *dic = @{}.mutableCopy;
        NSString *str;
        for (QYXDailyPlayInfoModel *playModel in model.playInfoX) {
            if ([playModel.name isEqualToString:@"标清"]) {
                str = playModel.url;
            }
            [dic setValue:playModel.url forKey:playModel.name];
        }
        
        QYXDailyPlayInfoModel *play = [model.playInfoX firstObject];
        self.playerView.videoURL = [NSURL URLWithString:play.url];
        // 返回按钮事件
        __weak typeof(self) weakSelf = self;
        self.playerView.hasDownload = YES;
        weakSelf.playerView.resolutionDic = dic;
        self.playerView.model = model;

        self.playerView.goBackBlock = ^{
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
            [weakSelf.playerView resetPlayer];
        };
    }
    return self;
}

- (instancetype)initWithPlayUrl:(NSString *)str AndPlaySort:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        self.playerView = [[ZFPlayerView alloc] init];
        [self.view addSubview:self.playerView];
        [self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(0);
            make.left.right.equalTo(self.view);
            // 注意此处，宽高比16：9优先级比1000低就行，在因为iPhone 4S宽高比不是16：9
            make.height.equalTo(self.playerView.mas_width).multipliedBy(9.0f/16.0f).with.priority(750);
        }];
              self.playerView.videoURL = [NSURL URLWithString:str];
        // 返回按钮事件
        __weak typeof(self) weakSelf = self;
        self.playerView.hasDownload = YES;
        weakSelf.playerView.resolutionDic = dic;
        
        self.playerView.goBackBlock = ^{
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
            [weakSelf.playerView resetPlayer];
        };
    }
    return self;
}




// 支持旋转方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
